﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;

namespace NappiSite.EasyCache
{
    internal static class SerializationHelper
    {
        public static byte[] Serialize(object obj)
        {
            using (var strm = new MemoryStream())
            {
                var formatter = new BinaryFormatter();
                formatter.Serialize(strm, obj);
                return strm.ToArray();
            }
        }

        public static object Deserialize(byte[] obj)
        {
            using (var strm = new MemoryStream())
            {
                var formatter = new BinaryFormatter();
                strm.Write(obj, 0, obj.Length);
                strm.Position = 0;
                return formatter.Deserialize(strm);
            }
        }
    }
}
